<?php
include "func.php";
$lastpage = ($lp = $_COOKIE['ramble_lastpage']) ? str_replace("~~~",";",$lp) : "forum.php?m=list";
if(!$_COOKIE['ramble_ubox']) setcookie('ramble_ubox','show',time()+60*60*24*14);
$showubox = ($_COOKIE['ramble_ubox'] == "show");
function nav()
{
    global $loggedin,$i18n;
    $nav = array    (
                        array("Forums","forum/list"),
                    );
    if($loggedin)
    {
        $nnav = array    (
            array($i18n->get('login/logout/link'),"login.php?m=logout&width=175&height=25&modal=true&buttons=logout",true,"logout"),
        );
    }
    else
    {
        if($_COOKIE['ramble_logout']) setcookie("ramble_logout",-1,time()-1000);
        $nnav = array    (
            array($i18n->get('login/login/link'),"login.php?width=600&height=225",true),
        );
    }
    $i = 1;
    foreach(array_merge($nav,$nnav) as $n)
    {
        $uri = str_replace("&","&amp;",$n[1]);
        $name = $n[0];
        echo "\n\t\t<li><a href=\"$uri\"";
        if(isset($n[2])) echo ' class="dialog"';
        if(isset($n[3])) echo ' id="'.$n[3].'"';
        if($i == 1) echo ' style="border-left: none;"';
        echo ">$name</a></li>";
        $i++;
    }
    echo "\n\t";
}
if($_GET['m'] == "nav")
{
    nav();
    exit;
}
elseif($_GET['m'] == "ubox")
{
    if($loggedin)
    {
        $uid = $_COOKIE['ramble_id'];
        $user = $api->query("user",$uid);
?>
<div id="userbox_close">
    <a onclick="uboxtoggle();">[<?=($showubox)?"^":"v"?>]</a>
</div>
<div id="userbox_content">
    <div class="avatar">
        <?if($ava = $user['avatar']) echo "<img src=\"uploads/avatars/$ava\" />"?>
    </div>
    <div class="info">
        <div>
        <?=$i18n->get("user/box/loggedin", array($uid,$user['name']))?><br />
        <?=$i18n->get("user/box/posts", $user['posts'])?>
        </div>
        <div id="useredit">
        <?=$i18n->get("user/box/edit")?>: <a href="user.php?m=edit;profile;<?=$uid?>"><?=$i18n->get("user/box/profile")?></a>, <a href="user.php?m=edit;preferences;<?=$uid?>"><?=$i18n->get("user/box/preferences")?></a>
        </div>
    </div>
</div>
<?
    }
    exit;
}
elseif($_GET['m'] == "conf")
{
    header("Content-Type: text/xml");
    echo "<conf>\n";
    foreach($config as $cat => $a)
    {
        if($cat == "mysql") continue;
        echo "\t<$cat>\n";
        foreach($a as $k => $v)
        {
            echo "\t\t<$k>$v</$k>\n";
        }
        echo "\t</$cat>\n";
    }
    echo "</conf>";
    exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <title>Ramble Forums</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <script src="combine.php?type=javascript&files=jquery.js,jquery-ui.js,php.js,func.js,main.js,pages.js" type="text/javascript"></script>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <script src="buttons.js.php" type="text/javascript"></script>
    <script src="i18n.js.php" type="text/javascript"></script>
    <link href="ui.css" rel="stylesheet" type="text/css" />
    <link rel="prefetch" href="/images/loading.gif" id="loadprefetch">
    <!--[if IE]><link href="ie.css" rel="stylesheet" type="text/css"><![endif]-->
</head>

<body>
<div id="userbox"<?if(!$loggedin){?> style="display: none;"<?}?>>
<?php
if($loggedin)
{
    $uid = $_COOKIE['ramble_id'];
    $user = $api->query("user",$uid);
?>
<div id="userbox_close">
    <a onclick="uboxtoggle();">[<?=($showubox)?"^":"v"?>]</a>
</div>
<div id="userbox_content">
    <div class="avatar">
        <?if($ava = $user['avatar']) echo "<img src=\"uploads/avatars/$ava\" />"?>
    </div>
    <div class="info">
        <div>
        <?=$i18n->get("user/box/loggedin", array($uid,$user['name']))?><br />
        <?=$i18n->get("user/box/posts", $user['posts'])?>
        </div>
        <div id="useredit">
        <?=$i18n->get("user/box/edit")?>: <a href="user.php?m=edit;profile;<?=$uid?>"><?=$i18n->get("user/box/profile")?></a>, <a href="user.php?m=edit;preferences;<?=$uid?>"><?=$i18n->get("user/box/preferences")?></a>
        </div>
    </div>
</div>
<?}?>
</div>
<div id="banner">
<h1>Ramble Forums</h1>
<div id="nav">
    <ul><?nav()?></ul>
</div>
</div>
<div id="content"></div>
<div id="dialog"></div>
</body>
</html>